<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        #container {
            width: 400px;
            margin: 10px auto;
        }

        .input, form + a {
            margin: 20px 20px;
            width: 250px;
        }

        .input > label {
            display: inline-block;
            width: 70px;
            text-align: right;
        }

        .input:last-child {
            text-align: center;
        }

        input[type=text], input[type=password] {
            outline: none;
        }

        input[type=submit], input[type=reset] {
            width: 60px;
        }

        form + a {
            text-decoration: none;
            color: blue;
        }

        .captcha {
            width: 380px;
        }

        .captcha > img {
            vertical-align: middle;
        }

        .hint {
            margin-left: 20px;
            color: red;
            font-size: 0.8em;
            height: 20px;
        }
    </style>
</head>
<body>
<div id="container">
    <h1>用户登录</h1>
    <hr>
    {{ msg }}
    <form action="/login/" method="post">
        {% csrf_token %}
        <input type="hidden" name='backurl' value="{{backurl}}">
        <div class="input">
            <label>用户名：</label>
            <input type="text" name="username">
        </div>
        <div class="input">
            <label>密码：</label>
            <input type="password" name="password">
        </div>
        <div class="input captcha">
            <label>验证码：</label>
            <input type="text" name="captcha">
            <img id="code" src="/captcha/" width="100">
        </div>
        <div class="input">
            <input type="submit" value="登录">
            <input type="reset" value="重置">
        </div>
    </form>
    <a href="/register/">注册新用户</a>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
    $(() => {
        $('#code').on('click',(evt) =>{
            $(evt.target).attr('src', '/captcha/?'+Math.random())
        })
    })
</script>
</body>
</html>